<?php
	
	/**
	 * 商品评论模型
	 */
	 class GoodsCommentModel extends Model{
	 	
		public $table = 'goodscomment';
		
		public $valudate = array(
			array('goods_gid','nonull','商品ID不能为空',2,3),
			array('users_uid','nonull','用户ID不能为空',2,3),
			array('gc_height','nonull','身高不能为空',2,3),
			array('gc_weight','nonull','体重不能为空',2,3),
			array('gc_content','nonull','评论内容不能为空',2,3)
		);
		
		public $auto = array(
			array('gc_time','time','function',2,3)
		);
		
		/**
		 * 给当前商品添加一条评论 
		 */
		public function addComment(){
			if(!$this->create()) return false;
			$data = $this->data;
			if($this->add($data)){
				//评论成功后返回相应的用户名再返回一个组合最后购买的那次
				$data['username'] = K('Users')->where("uid={$data['users_uid']}")->getField('username');				
				$data['combinestr'] = M()->join('__goods_order__ go JOIN __order_list__ ol ON ol.order_oid=go.oid')->where("go.users_uid={$data['users_uid']} AND ol.goods_gid={$data['goods_gid']}")->order('go.order_time DESC')->limit(1)->getField('ol.goods_combinestr');
				
				return $data;
			}else{
				return false;
			}
		}
		
		
	 }
	